<template>
  <div class="chat">
    <ul>
      <li :class="{'chat-mine': item.fromAccount === fromAccount}" v-for="(item, index) in chat.dealMessageEntryVoList" :key="index">
        <div class="chat-user">
          <img :src="item.fromAccount === fromAccount ? item.fromIcon : item.toIcon">
          <cite><i>{{ formatDate(item.msgTimeStamp*1000, 'YYYY-MM-DD HH:MM:SS') }}</i>{{ item.fromAccount === fromAccount ? item.fromNickName : item.toNickName }}</cite>
        </div>
        <div :class="['chat-text', { 'chat-text-active': chatItem.dealMsgContentVo.type }]" v-for="(chatItem, chatIndex) in item.dealMsgBodyVoList" :key="chatIndex">
          <span v-if="!chatItem.dealMsgContentVo.type">{{ chatItem.dealMsgContentVo.text }}</span>
          <el-image
            v-if="chatItem.dealMsgContentVo.type === 1"
            class="chat-img"
            :src="chatItem.dealMsgContentVo.text"
            :preview-src-list="srcList"
            @click="showImgList(chatItem.dealMsgContentVo.text)"
            z-index="3000"
            fit="cover">
            <div slot="error" class="image-slot">
              <i class="el-icon-picture-outline"></i>
            </div>
          </el-image>
          <videoBox v-if="chatItem.dealMsgContentVo.type === 2" :url="chatItem.dealMsgContentVo.text" :img="chatItem.dealMsgContentVo.videoCover" :time="chatItem.dealMsgContentVo.videoSecond || 0"/>
        </div>
      </li>
    </ul>
  </div>
</template>
<script>
import { formatDate } from '@/utils/utils'
export default {
  props: {
    fromAccount: {
      type: String,
      default: ''
    },
    chat: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      srcList: []
    }
  },
  methods: {
    // 放大图片
    showImgList (img) {
        let imgArr = []
        imgArr.push(img)
        this.srcList = imgArr
    },
    formatDate (time, type) {
      return formatDate(time, type)
    }
  }
}
</script>
<style lang="scss" scoped>
.chat{
  padding: 0 20px;
  overflow: auto;
  height: 90vh;
  .noMore{
    padding: 10px 0;
    text-align: center;
  }
  li{
    position: relative;
    font-size: 0;
    margin-bottom: 10px;
    padding-left: 60px;
    min-height: 68px;
    .chat-user, .chat-text{
      display: inline-block;
      *display: inline;
      *zoom: 1;
      vertical-align: top;
      font-size: 14px;
    }
    .chat-user{
      position: absolute;
      left: 3px;
      cite{
        position: absolute;
        left: 60px;
        top: -2px;
        width: 500px;
        line-height: 24px;
        font-size: 12px;
        white-space: nowrap;
        color: #999;
        text-align: left;
        font-style: normal;
        i{
          padding-left: 15px;
          font-style: normal;
        }
      }
      img{
        width: 40px;
        height: 40px;
        border-radius: 100%;
      }
    }
    .chat-text{
      position: relative;
      line-height: 22px;
      margin-top: 25px;
      padding: 8px 15px;
      background-color: #e2e2e2;
      border-radius: 3px;
      color: #333;
      word-break: break-all;
      &:after{
        content: '';
        position: absolute;
        left: -10px;
        top: 13px;
        width: 0;
        height: 0;
        border-style: dashed;
        border-color: transparent;
        overflow: hidden;
        border-width: 10px;
        border-top-style: solid;
        border-top-color: #e2e2e2;
      }
    }
    .chat-text-active {
      position: relative;
      padding: 0px;
      margin-top: 25px;
      line-height: 1;
      background-color: #fff;
      &:after{
        content: '';
        position: absolute;
        left: -10px;
        top: 13px;
        width: 0;
        height: 0;
        border-style: dashed;
        border-color: transparent;
        overflow: hidden;
        border-width: 10px;
        border-top-style: solid;
        border-top-color: #fff;
      }
      .chat-img {
        width: 160px;
        height: 80px;
        z-index: 1;
        border-radius: 6px;
      }
    }
  }
  .chat-mine{
    text-align: right;
    padding-left: 0;
    padding-right: 60px;
    .chat-user{
      left: auto;
      right: 3px;
      cite{
        left: auto;
        right: 60px;
        text-align: right;
        i{
          padding-left: 0;
          padding-right: 15px;
        }
      }
    }
    .chat-text{
      margin-left: 0;
      text-align: left;
      background-color: #5FB878;
      color: #fff;
      &:after{
        left: auto;
        right: -10px;
        border-top-color: #5FB878;
      }
    }
  }
}
</style>
